using System;
using System.Linq.Expressions;
using GeYiHome.PublicLibrary.Extension;

namespace GeYiHome.PublicLibrary.Rules
{
    public static class RuleExtension
    {
        //public static RuleBuilder RuleFor(this object source)
        //{
        //    return new RuleBuilder(source);
        //}
        public static RuleBuilder Valid<TSource>(this TSource source)
        {
            return new RuleBuilder(source);
        }

        public static RuleBuilder Valid<TSource, TOut>(this TSource source,
            Expression<Func<TSource, TOut>> expression)
        {
            var member = expression.GetMember();
            if (source==null)
                throw new ArgumentNullException(typeof (TSource).Name);
            var compiled = expression.Compile()(source);
            return new RuleBuilder(member, compiled);
        }
    }
}
